# Contributor: Milan P. Stanić <mps@arvanta.net>
# Contributor: Jakub Jirutka <jakub@jirutka.cz>
# Maintainer: Milan P. Stanić <mps@arvanta.net>
pkgname=pgbackrest
pkgver=2.51
pkgrel=0
pkgdesc="Reliable PostgreSQL backup & restore"
url="https://www.pgbackrest.org/"
arch="all"
license="MIT"
options="!check"  # FIXME: run tests
pkgusers="postgres"
pkggroups="postgres"
# postgresql package is not strictly required, just the "postgres" user that
# is created by this package. However, pgbackrest would be quite useless
# without PostgreSQL...
depends="postgresql"
checkdepends="perl"
makedepends="
	bzip2-dev
	libpq-dev
	libxml2-dev
	openssl-dev>3
	yaml-dev
	zlib-dev
	"
source="https://github.com/pgbackrest/pgbackrest/archive/release/$pkgver/pgbackrest-$pkgver.tar.gz
	$pkgname.logrotate
	pgbackrest.conf.in
	"
builddir="$srcdir/$pkgname-release-$pkgver"

prepare() {
	default_prepare

	local pgver=$(pg_config --version | sed -En 's/^PostgreSQL ([0-9]+)\..*/\1/p')
	sed "s/@@PG_VERSION@@/${pgver:-14}/" "$srcdir"/pgbackrest.conf.in > "$srcdir"/pgbackrest.conf
}

build() {
	cd "$builddir"/src

	./configure \
		--build=$CBUILD \
		--host=$CHOST \
		--prefix=/usr \
		--sysconfdir=/etc \
		--mandir=/usr/share/man \
		--localstatedir=/var
	make
}

package() {
	make -C src DESTDIR="$pkgdir" install

	install -D -m644 "$srcdir"/pgbackrest.conf -t "$pkgdir"/etc/pgbackrest/
	install -d -m755 "$pkgdir"/etc/pgbackrest/conf.d

	install -D -m644 "$srcdir"/$pkgname.logrotate "$pkgdir"/etc/logrotate.d/$pkgname

	install -d -m750 -o postgres -g postgres \
		"$pkgdir"/var/log/pgbackrest \
		"$pkgdir"/var/lib/pgbackrest

	install -d -m700 -o postgres -g postgres \
		"$pkgdir"/var/spool/pgbackrest
}

sha512sums="
b908b72dc9f0f42709b7f663d93b37bc1cb3cdf0a7594cb9a35c582f3e11c5bd7132a57a97e50b8c590f9a9faccd04f93d03999b234b39eb10a711b91c5290f1  pgbackrest-2.51.tar.gz
ded2377c531cea5709315c85007ddfed1f2eba0528eccd796bde4520d75f5cc6525918b3db8a073e892ebf04c943ab40cc7079dd306c7fdd344027748dae6570  pgbackrest.logrotate
5a1caab3f3aae94779211c4cab2bb5b7404f44f659d27cb657d2079dc0577773e3a6522b1382a1d9a843804bfcfe5aeae210a3aca9d2b585266bbb1df9a82fbb  pgbackrest.conf.in
"
